#include "EquipItem.h"
#include "../../model/proxy/ItemProxy.h"
#include "../../net/NCDefines.h"
#include "../../model/static/StaticItem.h"
#include "../../utils/LocalString.h"

EquipItem::EquipItem(void)
	:mName(NULL),mLevel(NULL),mType(NULL),mProperty(NULL),mPropertyTitle(NULL),
	mCheckBox(NULL),mIsClickBg(true)
{
}

EquipItem::~EquipItem(void)
{
	CC_SAFE_RELEASE(mName);
	CC_SAFE_RELEASE(mLevel);
	CC_SAFE_RELEASE(mType);
	CC_SAFE_RELEASE(mProperty);
	CC_SAFE_RELEASE(mPropertyTitle);
}

bool EquipItem::init()
{
	return true;
}

SEL_MenuHandler EquipItem::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onBgClick", EquipItem::onBgClick);
	return NULL;
}

SEL_CCControlHandler EquipItem::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAttributeBtnClick", EquipItem::onAttributeBtnClick);
	return NULL;
}

bool EquipItem::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName", CCLabelTTF *, this->mName);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mLevel", CCLabelTTF *, this->mLevel);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mType", CCLabelTTF *, this->mType);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mProperty", CCLabelTTF *, this->mProperty);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mPropertyTitle", CCLabelTTF *, this->mPropertyTitle);
	return false;
}

void EquipItem::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{
	mCheckBox = CheckBox::create("sprite/checkok_01.png","sprite/checkno_01.png",NULL, NULL);
	mCheckBox->setPosition(50, -200);
	addChild(mCheckBox);

	mEquipIcon = EquipIcon::create(this);
	mEquipIcon->setPosition(ccp(14, 9));
	mEquipIcon->setScale(0.22);
	addChild(mEquipIcon);
}

void EquipItem::onEnter()
{
	CCNode::onEnter();
}

void EquipItem::onExit()
{
	CCNode::onExit();
}

void EquipItem::_onNotification( CCObject* pSender )
{
	
}

void EquipItem::refresh()
{
	EquipInfo* itemData = (EquipInfo*)mData;
	EquipStatic* itemInfo = StaticItem::getSingletonPtr()->getEquipInfo(itemData->id);
	mName->setString(itemInfo->name);
	mLevel->setString(fcs("%d", itemData->level));
	mPropertyTitle->setString(StaticItem::getSingletonPtr()->getPropertyTitle(itemData->id));
	mProperty->setString(fcs("%d-%d", itemData->atkMin, itemData->atkMax));
	mType->setString(StaticItem::getSingletonPtr()->getTypeTitle(itemData->id));
	mEquipIcon->setInfo(itemData->id, itemInfo->quality);
}

void EquipItem::onBgClick(CCObject* pSender)
{
    
}

void EquipItem::showCheckBox( bool visible )
{
	mCheckBox->setVisible(visible);
}

bool EquipItem::isSelect()
{
    return mCheckBox->isSelect();
}

void EquipItem::onAttributeBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	if(!mIsClickBg) return;
	EquipInfo* itemData = (EquipInfo*)mData;
	Framework::getSingletonPtr()->popup("EquipDetailDialog", itemData);
}
